import sys
import os
import shutil

#finish in 2019.11.26

flag=int(sys.argv[1]) #1,CDNA;2,TCR/BCR
Workdir=sys.argv[2]
destDir=sys.argv[3]  #will create

def GetNeedFile(flag,Workdir,destDir):

    if not os.path.exists(destDir):
        os.makedirs(destDir)

    if flag == 1:
        needFilesList = ["outs/web_summary.html","outs/raw_feature_bc_matrix"]
    elif flag == 2:
        needFilesList = ["outs/clonotypes.csv","outs/filtered_contig_annotations.csv","outs/consensus.fasta","outs/web_summary.html"]


    for i in needFilesList:
        filePath="%s/%s" % (Workdir,i)
        if os.path.isfile(filePath):
            destFile="%s/%s" % (destDir,i)
            destDir2=os.path.dirname(destFile)

            stri="from %s to %s" % (filePath,destFile)
            print(stri)

            if not os.path.exists(destDir2):
                os.makedirs(destDir2)

            shutil.copy(filePath,destDir2)

        elif os.path.isdir(filePath):
            destDir="%s/%s" % (destDir,i)
            destDir2=os.path.dirname(destDir)

            stri="from %s to %s" % (filePath,destDir)
            print(stri)

            shutil.copytree(filePath,destDir)
          

GetNeedFile(flag,Workdir,destDir)

